package homework0303;

import org.w3c.dom.ls.LSLoadEvent;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ListDemo {
    public static void main(String[] args) {
        List<String> list=new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        list.add("one");
        System.out.println(list);

        String a=list.get(1);//获取第二个元素
        System.out.println(a);
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        Iterator<String> it=list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
        for (String s:list){
            System.out.println(s);
        }

        String old=list.set(2,"seven");
        System.out.println(list);
        System.out.println(old);//返回的是被替换下来的元素

        list.add(3,"nine");
        System.out.println(list);









    }
}
